//class Solution {
//    public static void main(String[] args) {
//         int[]nums= {5,7,7,8,8,10};
//        System.out.println(searchRange(nums, 8));
//    }
//    public static int[] searchRange(int[] nums, int target) {
//        if(nums.length == 0)return new int[]{-1,-1};
//        int left = 0 ;
//        int right = nums.length -1 ;
//        while(left < right){
//            int mid = left + (right-left)/2 ;
//            if(nums[mid] < target){
//                left = mid +1 ;
//            }else{
//                right = mid ;
//            }
//        }
//        right = binarySearch(nums,0,nums.length-1 , target);
//        if(left == -1)return new int[]{-1,-1};
//        return new int[]{left,right};
//
//    }
//    private  static int binarySearch(int[] nums , int left , int right ,int target){
//        while(left < right){
//            int mid = left + (right-left)/2 ;
//            if(nums[mid] > target){
//                right = mid -1 ;
//            }else{
//                left = mid ;
//            }
//        }
//        if(nums[right] == target){
//            return right ;
//        }
//        return -1 ;
//    }
//}
class Solution {
    public int[] searchRange(int[] nums, int target) {
        //排除 nums里什么都没有的情况;
        if(nums.length == 0) return new int[]{-1,-1};
        //找左边界
        int left = 0  , right = nums.length-1 ;
        while(left < right){
            int mid = left + (right-left)/2 ;
            if(nums[mid] < target){
                left = mid +1 ;
            }else{
                right = mid ;
            }
        }
        if(nums[left] != target){
            return new int[]{-1,-1};
        }
        int[] sum = new int[2] ;
        sum[0] = left;
        left = 0 ; right = nums.length-1 ;
        while(left < right){
            int mid = left + (right-left+1)/2;
            if(nums[mid] > target){
                right = mid-1 ;
            }else{
                left = mid ;

            }

        }
        sum[1] = right;
        return sum ;
    }
}